package com.zhou.project.modules.circle.circlePostsCommentYes.controller;

import com.zhou.project.modules.circle.circlePostsCommentYes.entity.CommentYes;
import com.zhou.project.modules.circle.circlePostsCommentYes.service.CommentYesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("circle/comYes")
@Api(tags = "[评论点赞]")
public class CommentYesController {

    @Autowired
    private CommentYesService commentYesService;

    @PostMapping
    @ApiOperation("添加取消点赞")
    @ApiImplicitParam(name = "postsId",value = "话题id",required = true,dataTypeClass = Integer.class)
    public void save(@RequestBody @Valid CommentYes entity){
        if (commentYesService.oneYes(entity.getCommentId())) {
            commentYesService.save(entity);
        }else {
            commentYesService.noYes(entity.getCommentId());
        }
    }

    @PostMapping("{id}")
    @ApiOperation("查询某评论的点赞数量")
    @ApiImplicitParam(name = "id",value = "评论id",required = true,dataTypeClass = Integer.class)
    public long countCommentYes(@PathVariable int id){
        return commentYesService.countCommentYes(id);
    }


}
